package com.yhao.stock.controller;


import com.yhao.stock.common.service.SHService;
import com.yhao.stock.common.service.THSService;
import com.yhao.stock.common.service.XQService;
import com.yhao.stock.entity.StockInfo;
import com.yhao.stock.mapper.StockInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yhao
 * @since 2023-11-30
 */
@Slf4j
@RestController
@RequestMapping("/financeInfo")
public class FinanceInfoController {

    @Autowired
    private THSService thsService;

    @Autowired
    private SHService shService;

    @Autowired
    private StockInfoMapper stockInfoMapper;

    @GetMapping("/thsTest")
    public String thsTest() {
        List<StockInfo> ahInfosLimit20 = stockInfoMapper.getAHInfosLimit20();
        thsService.getBaseInfo(ahInfosLimit20);
        return "success";
    }

    @GetMapping("/test")
    public String test() {

        String url1 = "https://q.stock.sohu.com/cn/605018/index.shtml";
        shService.getFinanceInfo(url1);


        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        String url2 = "https://q.stock.sohu.com/cn/603536/index.shtml";
        shService.getFinanceInfo(url2);

        // List<StockInfo> ahInfosLimit20 = stockInfoMapper.getAHInfosLimit20();
        // for (StockInfo stockInfo : ahInfosLimit20) {
        //     boolean financeInfoFlag = xqService.getFinanceInfo(stockInfo.getdCode(), stockInfo.getdName());
        //     if (!financeInfoFlag) {
        //         log.info("财务分析保存错误~~~~~" + stockInfo.getdCode() + "   financeInfoFlag=" + financeInfoFlag);
        //     }
        //
        //     try {
        //         Thread.sleep(5000);
        //     } catch (InterruptedException e) {
        //         e.printStackTrace();
        //     }
        // }


        return "Success";
    }

}
